package com.ruoyi.project.system.membershare.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.membershare.domain.MemberShare;
import com.ruoyi.project.system.membershare.service.IMemberShareService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户分享Controller
 * 
 * @author LCL
 * @date 2020-12-18
 */
@Controller
@RequestMapping("/system/membershare")
public class MemberShareController extends BaseController
{
    private String prefix = "system/membershare";

    @Autowired
    private IMemberShareService memberShareService;

    @RequiresPermissions("system:membershare:view")
    @GetMapping()
    public String membershare()
    {
        return prefix + "/membershare";
    }

    /**
     * 查询用户分享列表
     */
    @RequiresPermissions("system:membershare:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberShare memberShare)
    {
        startPage();
        List<MemberShare> list = memberShareService.selectMemberShareList(memberShare);
        return getDataTable(list);
    }

    /**
     * 导出用户分享列表
     */
    @RequiresPermissions("system:membershare:export")
    @Log(title = "用户分享", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberShare memberShare)
    {
        List<MemberShare> list = memberShareService.selectMemberShareList(memberShare);
        ExcelUtil<MemberShare> util = new ExcelUtil<MemberShare>(MemberShare.class);
        return util.exportExcel(list, "membershare");
    }

    /**
     * 新增用户分享
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户分享
     */
    @RequiresPermissions("system:membershare:add")
    @Log(title = "用户分享", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MemberShare memberShare)
    {
        return toAjax(memberShareService.insertMemberShare(memberShare));
    }

    /**
     * 修改用户分享
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MemberShare memberShare = memberShareService.selectMemberShareById(id);
        mmap.put("memberShare", memberShare);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户分享
     */
    @RequiresPermissions("system:membershare:edit")
    @Log(title = "用户分享", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MemberShare memberShare)
    {
        return toAjax(memberShareService.updateMemberShare(memberShare));
    }

    /**
     * 删除用户分享
     */
    @RequiresPermissions("system:membershare:remove")
    @Log(title = "用户分享", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberShareService.deleteMemberShareByIds(ids));
    }
}
